package main

import (
	"fmt"
)

//一个考试管理系统，利用继承实现
func main() {
	pupil := &Pupil{} //匿名结构的字段不可以在这里直接赋值
	pupil.Student.Name = "小路飞"
	pupil.Student.Age = 20
	pupil.Student.Score = 11.1

	pupil.Testing()
	pupil.SetScore(10)
	pupil.ShowInfo()

	//当单继承且字段名不重复的情况下，可以不用指定匿名结构
	//集成的字段当做自己的字段赋值
	graduate := &Graduate{}
	graduate.Name = "路飞"
	graduate.Age = 30
	graduate.Score = 100

	graduate.Testing()
	graduate.SetScore(90)
	graduate.ShowInfo()

}

type Student struct {
	Name  string
	Age   int
	Score float64
}

func (stu *Student) ShowInfo() {
	fmt.Printf("姓名：%v 年龄：%v 分数：%v \r\n", stu.Name, stu.Age, stu.Score)
}

func (stu *Student) SetScore(score float64) {
	stu.Score = score
}

type Pupil struct {
	Student
}

func (pupil *Pupil) Testing() {
	fmt.Println("小学生考试。。。")
}

type Graduate struct {
	Student
}

func (graduate *Graduate) Testing() {
	fmt.Println("大学生考试。。。")
}
